package com.hkbigdata.springbootdemo.controller;

import com.hkbigdata.springbootdemo.bean.Employee;
import com.hkbigdata.springbootdemo.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liuanbo
 * @creat 2024-11-13-14:42
 * @see 2194550857@qq.com
 */
@RestController
public class EmployeeController {
    @Autowired // =  自动从容器中找标注了次注解 的类型的对象，找到就赋值
    private EmployeeService employeeService;

    @RequestMapping("/getAllEmp")
    public Object getAllEmp() {
        return employeeService.findAll();
    }

    @RequestMapping("/emp")
    public Object getEmp(String op,Integer id,String lastname,String gender,String email) {
        Employee employee = new Employee(id, lastname, gender, email);
        switch (op){

            case "select": if (id == null){
                return "必须传入员工id！";
            }else {
                Employee e = employeeService.findById(id);
                return e == null ? "查无此人!" : e;
            }

            case "insert" : employeeService.add(employee);
                return "操作完成!";

            case "update": if (id == null){
                return "必须传入员工id！";
            }else {
                employeeService.update(employee);
                return  "操作完成!";
            }

            case "delete": if (id == null){
                return "必须传入员工id！";
            }else {
                employeeService.deleteById(id);
                return  "操作完成!";
            }

            default: return "请正确操作";
        }


    }
}
